<?php include_once('header.php'); ?>
<?php include_once('left_navigation.php'); ?>
<?php
	include('../classess/class_affiliate_user.php');
?>
<div class="col-lg-12"><!-- Start Middle Content Div-->
	<div class="box">
		<div class="row">
			<div class="col-lg-12" style="margin-top:-20px; text-align:center;">
                <div class="box" style="font-size:16px;">
					Your Refrence URL is 
					<a href="<?php echo ReferenceLink; ?>" target="_blank" style="text-decoration:none; color:blue; "><?php echo ReferenceLink; ?></a>	
                </div>
            </div>		
		</div><!--/row-->

		<div class="row">		
			<div class="col-lg-12">
				<div class="box">
					<div class="box-header" data-original-title>
						<h2><i class="fa fa-user"></i><span class="break"></span>Courses</h2>
						<div class="box-icon">
							<a href="table.html#" class="btn-minimize"><i class="fa fa-chevron-up"></i></a>
							<a href="table.html#" class="btn-close"><i class="fa fa-times"></i></a>
						</div>
					</div>
					<div class="box-content">
						<?php 
								if(isset($courses)){	
							?>
							<div class="alert alert-info">
								<div style="float: right; width: 5%;"><button type="button" class="close" data-dismiss="alert">&times;</button></div>
								<div style="float:left;width: 92%;word-wrap: break-word;"><?php echo $delete_activate_user; ?></div>
								<div style="clear:both;"></div>							
							</div>
							<?php
								}
							?>
						<div class="search_box">
							<div class="fl_left sel_label_search">Search:</div>
							<div class="fl_left" style="width:60%;">									
								<form method="POST" action="<?php echo $_SERVER['PHP_SELF'].'?home=1'; ?>" id="search_form" name="search_course_form">
									<input type="text" name="search_course_value" id="search_course_value" placeholder="Search" value="<?php if(isset($_POST['search_course_value'])){echo $_POST['search_course_value']; }else{ echo '';}  if(isset($_GET['search_course_value'])){echo $_GET['search_course_value']; }else{ echo '';}?>">&nbsp;
									<input type="submit" name="submit_course_search" id="submit_course_search" class="btn btn-blue srch_btn" value="Search">
								</form>

							</div>
							<div class="clear_fix"></div>
						</div>
						<table class="table table-striped table-bordered">
						  <thead>
							  <tr>
								  <th>S No.</th>
								  <th>Course Name</th>
								  <th>Course Fee</th>
								  <th>Course Description</th>
								  <th>Course Commission</th>
								  <th>Is Active</th>
							  </tr>
						  </thead>   
						  <tbody>
							<?php
									$record_limit = 25;

									$condition_search = '';
									$value = '';
									if(isset($_POST['search_course_value'])){										
										$value = trim($_POST['search_course_value']);
										
										if(!empty($value)){
											$cond_where = ' WHERE';
											$condition_search = $cond_where." (course_name like '%".$value."%' OR course_description like '%".$value."%' OR course_fee like '%".$value."%')";
										}
									}

									if(isset($_GET['search_course_value'])){	
										$value = $_GET['search_course_value'];
										
										if(!empty($value)){
											$cond_where = ' WHERE';

											$condition_search = $cond_where." (course_name like '%".$value."%' OR course_description like '%".$value."%' OR course_fee like '%".$value."%')";
										}
									}

									$select_count_course = "SELECT count(id) FROM tbl_courses".$condition_search;
									$result_count_course = mysql_query($select_count_course);

									$row = mysql_fetch_array($result_count_course);
									$record_count = $row[0];

									if( isset($_GET['crs_page']) )
									{
									   $crs_page = $_GET['crs_page'] + 1;
									   $crs_offset = $record_limit * $crs_page ;
									}
									else
									{
									   $crs_page = 0;
									   $crs_offset = 0;
									}

									$crs_serial_number = $crs_page*$record_limit;
									
									$crs_left_rec = $record_count - ($crs_page * $record_limit);
									
									$select_course = "select * from  tbl_courses".$condition_search." ORDER BY id DESC LIMIT ".$crs_offset.", ".$record_limit;
									$query_course = mysql_query($select_course) or die(mysql_error());
									
									$i = 1;
									if(mysql_num_rows($query_course)>0){
										while($row = mysql_fetch_array($query_course)){
											$crs_serial_number++;
											echo '
												<tr>
													<td>'.$crs_serial_number.'</td>
													<td>'.$row['course_name'].'</td>
													<td>'.$row['course_fee'].'</td>
													<td>'.$row['course_description'].'</td>
													<td>';
														if($row['course_commission']){
															echo $row['course_commission'].'%';
														}else{
															echo 'No Commission';
														}													
													echo '</td>
													<td>';
														if($row['is_active']){
															echo '<span class="label label-success">Active</span>';
														}else{
															echo '<span class="label label-default">Inactive</span>';
														}
													echo '</td>
												</tr>
											';
											$i++;
										}
									}else{
										echo '<tr>
											<td colspan="9" style="text-align:center;">No Records Found</td>
										</tr>';
									}

								?>						
						  </tbody>
					  </table>  
					 <?php		
							echo '<ul class="pagination">';
							if($record_count>$record_limit){
								if( $crs_page > 0 && $crs_left_rec > $record_limit)
								{
								   $last = $crs_page - 2;
								   echo '<li><a href="'.$_SERVER["PHP_SELF"].'?home=1&crs_page='.$last.'&search_course_value='.$value.'" class="anc_click">Prev</a></li> ';
								   echo '<li><a href="'.$_SERVER["PHP_SELF"].'?home=1&crs_page='.$crs_page.'&search_course_value='.$value.'" class="anc_click">Next</a></li>';
								}
								else if( $crs_page == 0 )
								{
								   echo '<li><a href="'.$_SERVER["PHP_SELF"].'?home=1&crs_page='.$crs_page.'&search_course_value='.$value.'" class="anc_click">Next</a></li>';
								}
								else if( $crs_left_rec < $record_limit || $crs_left_rec == $record_limit )
								{
								   $last = $crs_page - 2;
								   echo '<li><a href="'.$_SERVER["PHP_SELF"].'?home=1&crs_page='.$last.'&search_course_value='.$value.'" class="anc_click">Prev</a></li>';
								}
							}
							echo '</ul>';
						?>
					</div>
				</div>
			</div><!--/col-->

		</div><!--/row-->
	</div><!-- End Box Div-->
</div><!-- End Middle Content Div-->
<?php include_once('footer.php'); ?>
<script>
	$ = jQuery.noConflict();
	$(document).ready(function(){	
		$('.close').click(function(){
			$('.alert-info').addClass('hide');
		});

		$('#add_user').click(function(){
			document.add_course_form.submit();
		});

		$('#submit_course_search').click(function(){
			document.search_course_form.submit()
		});
	});
		
	
</script>